<?php
@require("php_config_init.php");
@require("php_config_mysql.php");
$userid = $_GET["userid"];
$goodsid = $_GET["goodsid"];
$goodsnum = $_GET["goodsnum"];
$measure_id = $_GET["measure_id"];
$birthday_card = $_GET["birthday_card"];
//sql语句
$sql = "select id,goodsid,userid,goodsnum from cart where status = 1 and userid = '$userid' and goodsid = '$goodsid'";
//执行sql语句
$result = mysql_query($sql);
//解析一行数据，没有返回false
$item = mysql_fetch_array($result);
$obj = array();
if($item){
    $sql = "update cart set goodsnum = goodsnum+$goodsnum,birthday_card = '$birthday_card' where goodsid = '$goodsid' and userid = '$userid'";
    mysql_query($sql);
    $count = mysql_affected_rows();
    if($count > 0){
        $obj["code"] = 1;
        $obj["msg"] = "加入购物车成功";
    }else{
        $obj["code"] = 0;
        $obj["msg"] = "加入购物车失败";
    }
}else{
    $sql = "insert into cart (goodsid,userid,goodsnum,birthday_card,measure_id) values ('$goodsid','$userid','$goodsnum','$birthday_card','$measure_id')";
    mysql_query($sql);
    $count = mysql_affected_rows();
    if($count > 0){
        $obj["code"] = 1;
        $obj["msg"] = "加入购物车成功";
    }else{
        $obj["code"] = 0;
        $obj["msg"] = "加入购物车失败";
    }
}
echo json_encode($obj);
?>